﻿using ProjectFootball.MVC.Foundation.ResourceLibrary;
using WebMatrix.WebData;

namespace System.Security.Principal
{
    public static class UserExtensions
    {
        public static int GetUserId(this IPrincipal user)
        {
            return WebSecurity.GetUserId(user.Identity.Name);
        }

        public static RoleType GetUserRoleType(this IPrincipal user)
        {
            if (user != null)
            {
                if (user.IsInRole("User"))
                    return RoleType.User;

                if (user.IsInRole("Superuser"))
                    return RoleType.Superuser;

                if (user.IsInRole("Admin"))
                    return RoleType.Admin;
            }

            return RoleType.Anonymous;
        }

        public static bool IsApprover(this IPrincipal user)
        {
            RoleType roleType = user.GetUserRoleType();
            return roleType == RoleType.Admin || roleType == RoleType.Superuser;
        }
    }
}